package com.lovo.ssc.controller;

import com.lovo.ssc.service.impl.CartService;
import com.lovo.ssc.vo.Cart;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 购物车控制器
 * @author WXL
 * @date 2022/7/7
 */
@RestController
@RequestMapping("/cart")
@Api(tags = "购物车控制类")
public class CartController {

    @Autowired
    private CartService service;

    @ApiOperation("查看购物车商品")
    @GetMapping("findByCart")
    public Cart findByCart(){
        return service.findByCart();
    }

    @ApiOperation("添加购物车商品")
    @PostMapping("addGoods/{goodsId}/{buyNum}")
    public void addGoods(@PathVariable int goodsId,@PathVariable int buyNum){
        service.addToCart(goodsId, buyNum);
    }

    @ApiOperation("按编号删除购物车商品")
    @DeleteMapping("delGoodsById/{goodsId}")
    public void delGoodsById(@PathVariable int goodsId){
        service.delGoodsById(goodsId);
    }

    @ApiOperation("清空购物车")
    @DeleteMapping("clearCart")
    public void clearCart(){
        service.clearCart();
    }

    @ApiOperation("按编号修改购物车商品数量")
    @PutMapping("updateGoodsNumById/{goodsId}/{buyNum}")
    public void updateGoodsNumById(@PathVariable int goodsId,@PathVariable int buyNum){
        service.updateGoodsNumById(goodsId,buyNum);
    }
}
